package com.rentplant.controller;

import com.alibaba.fastjson.JSONObject;
import com.rentplant.Pojo.inform;
import com.rentplant.service.impl.informServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController//让它知道这是controller
@RequestMapping("/inform")
public class informController {
    @Autowired
    private informServiceImp informserviceimp;

    @GetMapping("/inform")
    //查找公告信息
    public List<inform> inform(){
        try{
            return informserviceimp.inform();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }


    //    管理通信
//    查询公告信息并分页
    @RequestMapping("/allInform")
    public List<inform>allInform(@RequestBody JSONObject req){
        try {
            return informserviceimp.allInform(req);
        }catch (Exception e){
            throw  new RuntimeException(e);
        }
    }

    //    查询公告信息并分页
    @RequestMapping("/allInforms")
    public List<inform>allInforms(){
        try {
            return informserviceimp.allInforms();
        }catch (Exception e){
            throw  new RuntimeException(e);
        }
    }

    //    修改公告信息
    @RequestMapping("/updateInform")
    public boolean updateInform(@RequestBody JSONObject req){
        try {
            return informserviceimp.updateInform(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    发布公告
    @RequestMapping("/addInform")
    public boolean addInform(@RequestBody JSONObject req){
        try {
            return informserviceimp.addInform(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    条件查找
    @RequestMapping("/searchInform")
    public List<inform> searchInform(@RequestBody JSONObject req){
        try {
            return informserviceimp.searchInform(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    条件查找
    @RequestMapping("/searchInforms")
    public List<inform> searchInforms(@RequestBody JSONObject req){
        try {
            return informserviceimp.searchInforms(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    删除公告
    @RequestMapping("/delById")
    public boolean delById(@RequestBody JSONObject req){
        try {
            return informserviceimp.delById(req);
        }catch (Exception e){
            throw  new RuntimeException(e);
        }
    }

}
